﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Web;

namespace ImobitechDao
{

    public sealed class Contexto
    {
        // Inicialização estática - thread-safe.
        private static readonly Contexto instance = new Contexto();

        // Instância do ObjectContext.
        private readonly ImobitechEntities context;

        // Construtor privado - Singleton pattern.
        private Contexto()
        {
            context = new ImobitechEntities();
        }

        // Retorna instância única da classe.
        public static Contexto Instance
        {
            get
            {
                return instance;
            }
        }

        // Retorna ObjectContext
        public ImobitechEntities Context
        {
            get
            {
                return context;
            }
        }
    } 


    //static class Contexto
    //{
    //    private static ImobitechEntities _contexto;

    //    public static ImobitechEntities CurrentContext
    //    {
    //        get
    //        {

    //            if (((HttpContext.Current != null)))
    //            {

    //                object sdc = HttpContext.Current.Items[" SistemaDataContext"];

    //                if (sdc == null)
    //                {

    //                    sdc = new ImobitechEntities();

    //                    HttpContext.Current.Items[" SistemaDataContext"] = sdc;
    //                }

    //                return (ImobitechEntities)sdc;
    //            }
    //            else
    //            {
    //                if (_contexto == null)
    //                {
    //                    _contexto = new ImobitechEntities();
    //                }

    //                return _contexto;

    //            }
    //        }
    //    }
    //}
}
